package liu.first;

import static org.junit.Assert.*;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

import org.junit.Test;

/**
 * 1、有一个数据文件:123 34  17  651234  345....这些数据都是随机产生的,
 * 求：编写程序读出该文件.并将其以从大到小的顺序输出到另一个文件中.
 * @author My
 *
 */
public class FileRead {
	
	private static InputStream in;
	private static BufferedInputStream bis;
	
	public static void main(String[] args) {
		
		
		//1.从文件中读取数据
		try {
			in = new FileInputStream("c:/FileRead.txt");
			bis=new BufferedInputStream(in);
			byte[] b=new byte[1024];
			int len=0;
			StringBuilder sb=new StringBuilder();
			
			while((len=bis.read(b))!=-1){
			String st=new String(b, 0,len);
			st=st+",";
			sb.append(st);
			System.out.println(sb.toString());
			}
			//2冒泡排序
			
			String[] array= sb.toString().split(",");
			
			
			int lenght=array.length;
			for(int i=0;i<lenght-1;i++){
				for(int j=1;j<lenght-1;i++){
					int first=Integer.parseInt(array[j-1]);
					int second=Integer.parseInt(array[j]);
					int temp=0;
					if(first>second){
						second=temp;
						second=first;
						first=temp;
					}
				}
			}
			for (String s : array) {
				System.out.println(s);
			}

			/*int len1=array.length;
			for(int i=0;i<len1-1;i++){
				//列
				for(int j=1;j<len1;j++){
					int first=j-1;
					int second=j;
					String temp;
					if(array[first]>array[second]){
						temp=array[second];
						array[second]=array[first];
						array[first]=temp;
					}
				}*/

			
			
			
			
		
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			
				try {
					bis.close();
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}
	}
	
	@Test
	public void testName() throws Exception {
		String[] a={"33","343"};
	
		
		
			
		
	}
}
	
